package com.example.lanouhn.bantangapp.activities.activities;

import android.os.Bundle;
import android.os.Message;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.example.lanouhn.bantangapp.R;
import com.example.lanouhn.bantangapp.activities.fragments.Fragment_CalendarActivity;

import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;


/**
 * 首页 签到  页面
 * Created by lanouhn on 16/7/26.
 */
public class Home_Sign_Activity extends FragmentActivity {

    private ImageView back;//返回
    private ImageView iv_qian_dao_ri_li;//签到日历
    private ImageView iv_qian_dao_rili;//更换图片
    private ImageView iv_fen_xiang; //分享
    private ImageView iv_wen_hao;
    private FrameLayout fr1;//隐藏的fragmentlayout 日历



    private android.os.Handler handler = new android.os.Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 0:
                    return;
                case 1:
                    iv_fen_xiang.setVisibility(View.VISIBLE);
                    iv_wen_hao.setVisibility(View.GONE);
                    break;

            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home_sign);

        //分享
        ShareSDK.initSDK(this, "sharesdk的appkey");

        back = (ImageView) findViewById(R.id.back);
        iv_fen_xiang = (ImageView) findViewById(R.id.iv_fen_xiang);
        iv_qian_dao_ri_li = (ImageView) findViewById(R.id.iv_qian_dao_ri_li);
        iv_qian_dao_rili = (ImageView) findViewById(R.id.iv_qian_dao_rili);
        fr1 = (FrameLayout) findViewById(R.id.fr1);
        iv_wen_hao = (ImageView) findViewById(R.id.iv_wen_hao);

        initLinstener();
        getSupportFragmentManager().beginTransaction().add(R.id.fr1, new Fragment_CalendarActivity()).commit();


        new Thread(new Runnable() {
            @Override
            public void run() {

                try {
                    Thread.sleep(1000);

                    handler.sendEmptyMessage(1);


                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

    }

    //监听事件
    private void initLinstener() {
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

//签到日历事件
        iv_qian_dao_ri_li.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                fr1.setVisibility(View.VISIBLE);//打开日历布局
                iv_qian_dao_rili.setVisibility(View.VISIBLE);//切换图片
                iv_qian_dao_ri_li.setClickable(false);
            }
        });
        iv_qian_dao_rili.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                fr1.setVisibility(View.INVISIBLE);//关闭日历布局
                iv_qian_dao_rili.setVisibility(View.INVISIBLE);
                iv_qian_dao_ri_li.setClickable(true);
            }
        });
        iv_fen_xiang.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showShare();
            }
        });
    }


    private void showShare() {
        ShareSDK.initSDK(this);
        OnekeyShare oks = new OnekeyShare();
        //关闭sso授权
        oks.disableSSOWhenAuthorize();

        // title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间等使用
        oks.setTitle("标题");
        // titleUrl是标题的网络链接，QQ和QQ空间等使用
        oks.setTitleUrl("http://sharesdk.cn");
        // text是分享文本，所有平台都需要这个字段
        oks.setText("我是分享文本");
        // imagePath是图片的本地路径，Linked-In以外的平台都支持此参数
        //oks.setImagePath("/sdcard/test.jpg");//确保SDcard下面存在此张图片
        // url仅在微信（包括好友和朋友圈）中使用
        oks.setUrl("http://sharesdk.cn");
        // comment是我对这条分享的评论，仅在人人网和QQ空间使用
        oks.setComment("我是测试评论文本");
        // site是分享此内容的网站名称，仅在QQ空间使用
        oks.setSite(getString(R.string.app_name));
        // siteUrl是分享此内容的网站地址，仅在QQ空间使用
        oks.setSiteUrl("http://sharesdk.cn");

        // 启动分享GUI
        oks.show(this);
    }
}